package com.otaku;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;

import com.otaku.consts.GlobalConst;

public class BaseController {
	protected Logger logger = LoggerFactory.getLogger(getClass());
	private Map<String, Object> getMap(){
		Map<String, Object> map=new HashMap<>();
		map.put(GlobalConst.KEY_CODE, "200");
		map.put(GlobalConst.KEY_MSG, "");
		map.put("time", System.currentTimeMillis());
		return map;
	}
	protected ModelAndView convertData(DataConvertor dataConvertor) {
		try {
			Map<String, Object> map=getMap();
			map.put("data", dataConvertor.getData());
			ModelAndView modelAndView=new ModelAndView(getViewPath(dataConvertor),map);
			 return modelAndView;
		} catch (Exception e) {
			logger.info("",e);
			return null;
		}
	}
	protected String getViewPath(DataConvertor dataConvertor){
		 return dataConvertor.getViewPath();
	}
	
}
